
  <template>
  <div class="bf-commont-template">
    <!--<h3>年假管理</h3> -->
    <!-- <div class="clearfix bf-top-button">
      <div class="float-l">
        <el-button @click="showAdd" type="primary">新增</el-button>
      </div>
    </div> -->
    <div class="clearfix box">
      <div class="org-content float-l ">
          <div class="block shadow-r org-box">
            <div class="margin-r border padding border-radius org-inner bf-row-datapick">
              <div>
                <div >
                  <bf-org :userOrg='userOrg' @nodeClick="nodeClick"></bf-org>
                </div>
              </div>
            </div>
          </div>
      </div>
      <div class="day-conent float-l el-tabs">

        <div class="clearfix bf-top-button">
          <div class="float-l">
            <el-button @click="showAdd" type="primary">新增</el-button>
          </div>
          <div class="float-r">
            <div class="float-l">
              <el-input placeholder="请输入休假日期搜索" prefix-icon="el-icon-search" v-model="searchData" @keyup.enter.native="quickSearch"></el-input>
            </div>
            <div class="float-l padding-l">
              <el-button @click="showSearch" type="primary">高级筛选</el-button>
            </div>
          </div>
        </div>

        <bf-table :data="userData" :setting="listSetting" :rowAction="rowAction" @editSubmit="editSubmit" @pageChange="pageChange" :editRules="editRules" ref="table"></bf-table>
      </div>
    </div>
    <!-- 添加 -->
    <bf-table-edit :editForm='addHolidaySetting1' ref='addeRef' @formSubmit='addSubmit' :editRules="editRules"></bf-table-edit>
    <!--编辑-->
    <bf-table-edit :editForm='addHolidaySetting' ref='editRef' @formSubmit='updateSubmit' :editRules="editRules"></bf-table-edit>
    <!--高级搜索 -->
    <bf-table-search :editForm='searchSetting' ref='searchRosterRef' @formSubmit='searchRosterSubmit'></bf-table-search>

  </div>
</template>

<script>

import { searchSetting, addHolidaySetting1, listSetting, addHolidaySetting } from './table.setting.js'
import { getAttendanceList, findDetail, addLeave, editLeave, detailDate } from './api.js'
import { getUserInFo } from '../../../../api/common.js'
export default {
  data() {
    return {
      searchSetting: searchSetting,
      searchData: '',
      userData: {},
      year: '',
      listSetting: listSetting,
      addHolidaySetting: addHolidaySetting,
      addHolidaySetting1: addHolidaySetting1,
      userOrg: true,
      userId: '',
      isEmployee: 0,
      rowAction: [
        {
          label: '详情',
          click: (item) => {
            // this.$refs.editRef.showEdit(item)
            // this.findDetailById(item.scope.row.id, this.$refs.editRef.show)
            this.$refs.table.showDetail(item)
          }
        },
        {
          label: '编辑',
          click: (item) => {
            // this.$refs.editRef.showEdit(item)
            this.findDetailById(item.scope.row.id, this.$refs.editRef.show)
          }
        },
        {
          label: '删除',
          click: (item) => {
            this.$refs.table.showDelete(item)
          }
        }
      ],
      editRules: {
        holidayDays: [
          { required: true, message: '请输入年假天数', trigger: 'blur' }
        ],
        holidayType: [
          { required: true, message: '请输入假期类型', trigger: 'blur' }
        ],
        holidayDate: [
          { required: true, message: '请输入休假日期', trigger: 'blur' }
        ],
        userId: [
          { required: true, message: '请选择员工', trigger: 'blur' }
        ]

      },
      searchParams: { // 搜索条件
        page: 1
      }
    }
  },
  mounted: function() {
    getUserInFo().then(response => {
      if (response.data) {
        this.searchParams.employeeNo = response.data.employeeNo
        this.findList()
      }
    })
  },
  methods: {
    nodeClick(node, b, c) {
      this.userId = node.id
      this.isEmployee = node.isEmployee
      if (this.isEmployee == '1') {
        this.searchParams.employeeNo = node.id
        this.findList()
      }
    },
    findList() {
      getAttendanceList(this.searchParams).then((response) => {
        this.userData = response
      })
    },

    findDetailPage(id, showCall) { // 详情
      findDetail(id).then((response) => {
        showCall(response.data)
      })
    },
    addSubmit(form) { // 新增保存
      const base = {
        employeeNo: form.userId

      }
      const obj = Object.assign(form, base)
      addLeave(obj).then((response) => {
        if (response.success) {
          this.$message({
            message: '操作成功!',
            type: 'success'
          })
          this.findList()
          this.$refs.addeRef.hiden()
        }
      })
    },

    updateSubmit(form) {
      editLeave(form).then((response) => {
        if (response.success) {
          this.$message({
            message: '操作成功!',
            type: 'success'
          })
          this.findList()
          this.$refs.editRef.hiden()
        }
      })
    },


    editSubmit(params, formType, formList) {
      console.log(params, formType, formList)
      if (formType === 'delete') {
        const id = params.row.id
        this.deleteHoliday(id)
      }
    },
    deleteHoliday(id) {
      detailDate(id).then((response) => {
        if (response.success) {
          this.$message({
            message: '删除用户成功!',
            type: 'success'
          })
        }
        this.findList()
      })
    },

    findDetailById(id, showCall) { // 详情
      findDetail(id).then((response) => {
        this.detailData = response.data;
        showCall(this.detailData)
      })
    },

    searchRosterSubmit(form) { // 高级搜索
      this.searchParams.page = 1
      this.searchParams.holidayDate = form.holidayDate
      this.searchParams.holidayType = form.holidayType
      this.searchParams.year = form.year
      this.findList()
      this.$refs.searchRosterRef.hiden()
    },
    pageChange(pageObj) { // 分页
      this.searchParams.page = pageObj.page
      this.searchParams.pageSize = pageObj.pageSize
      this.findList()
    },
    showSearch() {
      this.$refs.searchRosterRef.show()
    },
    showAdd() {
      this.$refs.addeRef.show({})
    },
    quickSearch() {
      this.searchParams.page = 1
      this.searchParams.holidayDate = this.searchData
      this.findList()
    }
  }
}
</script>

<style scoped>
.org-content {
  width: 20%;
  height: 100px;
}

.day-conent {
  width: 80%;
}

.box {
  padding: 0 16px;
}

table {
  width: 100%;
  border-top: 1px solid #eee;
  border-left: 1px solid #eee;
}

table>tr>td,
table>tr>th {
  border-bottom: 1px solid #eee;
  border-right: 1px solid #eee;
  text-align: center;
  padding: 7px 0;
  background: #FAFAFA;
}

table>tr>th {
  padding: 12px 0;
  background: #F5F8FA;
}
.org-box{
  margin-right: 16px;
  padding-top: 16px;
  min-height: 600px;

}
.org-inner{
  min-height: 600px;
  margin-bottom: 10px;
}

</style>
